<!--
* @description 留言版
* @fileName message.vue
* @author huangyu
* @date 2022/06/23 22:24:07
!-->
<template>
    <div>
        <van-nav-bar title="留言板" />
        <div style="margin-top:10px;">
            <van-form @submit="addMsg" label-width="4.2em">
                <van-field  rows="2" autosize type="textarea" v-model="msg" label="留言内容" placeholder="请输入留言内容" :rules="[{ required: true, message: '请填写留言内容' }]" />
                <div style="margin: 16px;">
                    <van-button round block type="info" native-type="submit">提交</van-button>
                </div>
            </van-form>
        </div>
        <div style="margin:10px 0;">
            <van-cell v-for="(item,index) in msgList" :key="index">
                <div><strong>{{item.content}}</strong></div>
                <div style="color:#999;font-size:12px;">{{item.createTime | formatDate}}</div>
            </van-cell>
        </div>
    </div>
</template>

<script>
import { get } from '@/common/app.js'
import { formatDate } from '@/common/unit.js'
import { Toast } from 'vant';
export default {
    components: {},
    data() {
        return {
            msg: "",
            msgList: [],
        }
    },
    mounted() {
        this.getMsg()
    },
    methods: {
        addMsg(){
            if(this.msg){
                let params = {
                    type: 'getAionMsg',
                    data: {
                        type: 'addMsg',
                        content: this.msg,
                        status: 1,
                    },
                }
                get('game',params).then(res=>{
                    if(res){
                        if(res.id){
                            Toast.success('留言成功！');
                            this.getMsg()
                        }
                    }
                })
            }else{
                Toast.fail('请填写内容！');
            }
        },
        getMsg(){
            let params = {
                type: 'getAionMsg',
                data: {
                    type: 'getMsg',
                },
            }
            get('game',params).then(res=>{
                if(res){
                    this.msgList = res.data.reverse()
                }
            })
        },
    },
    filters: {
        formatDate(time) {
        var date = new Date(time);
        let res = formatDate(date, "yyyy-MM-dd hh:mm:ss");
        return res;
        },
    }
}
</script>

<style scoped>
</style>